package gof23.structure.decorator;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberInputStream;
import java.io.LineNumberReader;
import java.io.Reader;

public class JDKDecoratorDemo {

	public static void main(String[] args) throws Exception {
		
		byte bytes[] = {
									97,
									13,
									98
								};
		/**
		 * InputStream 为被装饰的组件
		 * FilterInputStream 为装饰者
		 * ByteArrayInputStream 为具体组件
		 */
		LineNumberInputStream inputStream = new LineNumberInputStream(new BufferedInputStream(new ByteArrayInputStream(bytes)))  ;
		//InputStream inputStream = new ByteArrayInputStream(bytes) ;
		
		inputStream.mark(3);
		int value;
		while((value = inputStream.read())!=-1){
			System.out.println(inputStream.getLineNumber());
		}
		inputStream.reset();
		
		LineNumberReader reader = new LineNumberReader(new InputStreamReader(inputStream));
		String str;
		while((str = reader.readLine())!=null){
			System.out.println(str);
		}
	}
}
